import com.sun.j3d.loaders.Scene;
import java.awt.Color;
import java.util.Map;

import javax.media.j3d.Appearance;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.Bounds;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.DirectionalLight;
import javax.media.j3d.Material;
import javax.media.j3d.RenderingAttributes;
import javax.media.j3d.Shape3D;
import javax.media.j3d.Transform3D;
import javax.media.j3d.TransformGroup;
import javax.vecmath.Color3f;
import javax.vecmath.Vector3f;

public class ModelBuilder 
{
    public static TransformGroup getModel(Scene s, BoundingSphere b)
    {
        BranchGroup group = new BranchGroup();
        Map<String, Shape3D> nameMap = s.getNamedObjects();
        group.removeAllChildren();
        
        TransformGroup model = new TransformGroup();
        model.addChild(s.getSceneGroup());
        
        model.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        ustawAK47(model);
        ustawSwiatla(model);

        return model;
    }
    
    private static void ustawAK47(TransformGroup model) 
    {
        Transform3D transform = new Transform3D();
        transform.rotY(90D); 
        transform.setTranslation(new Vector3f(0F, 0F, -2F));
        model.setTransform(transform);
    }
    
    private static void ustawSwiatla(TransformGroup model) {
        Color3f lightColor = new Color3f(Color.BLUE);
        Vector3f lightDirection = new Vector3f(-1F, -1F, -1F);
        DirectionalLight light = new DirectionalLight(lightColor, lightDirection);
        Bounds influenceRegion = new BoundingSphere();
        light.setInfluencingBounds(influenceRegion);
        model.addChild(light);
    }
    
    private static void ustawTransformacje(TransformGroup... tgp) 
    {
        for (TransformGroup tg : tgp) 
        {
            tg.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
        }
    }
}
